# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：   aiui
   Author :      wuqianyong
   date：        2018/11/12
-------------------------------------------------
   Change Activity:
                   2017/4/1:
-------------------------------------------------
Description :
 

"""
__author__ = 'wuqianyong'
# -*- coding: utf-8 -*-
import requests
import time
import hashlib
import base64
import json

URL = "https://openapi.xfyun.cn/v2/aiui"
APPID = "5acf4732"
API_KEY = "eca736f9969d46ca8fc65a6f597654cf"


# AUDIO_PATH = "audio_test.wav"


def getHeader(aue='', engineType='', scene=''):
    curTime = str(int(time.time()))
    param_dict = {'result_level': 'complete',
                  'auth_id': '2bd69630f55d4428b41b7fc38441f3f3',
                  'data_type': 'text',
                  'scene': 'main'}
    param = json.dumps(param_dict)
    paramBase64 = base64.b64encode(param.encode()).decode()

    m2 = hashlib.md5()
    m2.update('{}{}{}'.format(API_KEY, curTime, paramBase64).encode())
    checkSum = m2.hexdigest()

    header = {
        'X-CurTime': curTime,
        'X-Param': paramBase64,
        'X-Appid': APPID,
        'X-CheckSum': checkSum,
    }
    print(header)
    return header


def getBody(filepath):
    binfile = open(filepath, 'rb')
    data = binfile.read()
    return data


r = requests.post(URL, headers=getHeader(), data="我想买_".encode())
content_str = str(r.content, encoding='utf-8')
content_dict = json.loads(content_str)
print(content_dict)

if __name__ == '__main__':
    pass
